/**************************************************
|	File:		Armor.cpp
|	Author:		Benjamin Budian
|	Course:		SGD
|	Purpose:	Handles the armor drops
**************************************************/
#include "Armor.h"
#include "BitmapFont.h"
#include "Game.h"

#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers//CSGD_EventSystem.h"
#include "../SGD Wrappers/SGD_String.h"

CArmor::CArmor(void)
{
	m_nImageID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/images/Player/Golden Armor/Male/bb_Armor_Drops.png"));
	CSGD_EventSystem::GetInstance()->RegisterClient("DEBUG",this);

	m_eType = ENT_ARMOR;
	SetWidth(32);
	SetHeight(32);
	m_bDebug = false;
}

CArmor::~CArmor(void)
{
	CSGD_EventSystem::GetInstance()->UnregisterClientAll(this);
}

void CArmor::Update( float fElapsedTime ){}

void CArmor::Render( void ){

	if(m_bDebug){
		RECT rCollisionBox = GetRect();
		CSGD_Direct3D::GetInstance()->DrawRect(rCollisionBox, D3DCOLOR_ARGB(127,255,255,0));

		TOSTRINGSTREAM toss;

		toss << "(" << GetPosX() << ", " << GetPosY() << ")\n"
			<< "Armor Type: " << m_eArmorType << '\n'
			<< "Armor Value: " << m_eArmorValue << '\n';

		CBitmapFont* pFont = CGame::GetInstance()->GetFont();

		pFont->Draw(toss.str().c_str(),(int)(GetPosX() + GetWidth()), (int)(GetPosY()), .34f,D3DCOLOR_ARGB(255,0,0,0));

	}

	RECT rRect = { m_eArmorType*32, 0, m_eArmorType*32 + 32, 32 };

	CSGD_TextureManager::GetInstance()->Draw(m_nImageID, (int)GetPosX(), (int)GetPosY(), 1.0f, 1.0f, &rRect);
}

void CArmor::SetArmorType(ArmorPieces eArmorType){

	switch(eArmorType){
	case HEAD:
		m_eArmorValue = HEAD_VALUE;
		break;
	case HANDS:
		m_eArmorValue = HANDS_VALUE;
		break;
	case LEGS:
		m_eArmorValue = LEGS_VALUE;
		break;
	case SHOULDER:
		m_eArmorValue = SHOULDER_VALUE;
		break;
	case FEET:
		m_eArmorValue = FEET_VALUE;
		break;
	case CHEST:
		m_eArmorValue = CHEST_VALUE;
		break;
	}

	m_eArmorType = eArmorType;
}

void CArmor::HandleEvent( CEvent* pEvent ){

	if(pEvent->GetEventID() == "DEBUG"){
		m_bDebug = !m_bDebug;
	}

}


